<?php
/**
 * @author qingyu8@staff.weibo.com
 * @date 2018/05/20
 */
namespace common\tool;

use common\logic\User;
use Yii;

class Alarm {
    public static function sys($msg, $type = 'Type') {
        $mail = Yii::$app->mailer->compose();
        $mail->setTo(['136101043@qq.com']);
        $mail->setSubject("酷潜系统报警 $type " . date('Y/m/d H:i:s'));
        $mail->setHtmlBody($msg);
        try {
            if (!$mail->send()) Yii::error('mail send fail', __METHOD__);
        } catch (\Exception $e) {
            Yii::error($e->getMessage(), __METHOD__);
        }
    }

    public static function business($msg, $type = 'Type', $uid = null) {
        if(!$uid) $uid=Yii::$app->user->id;
        $username=$uid ? User::getNames([$uid])[$uid] : '';
        $mail = Yii::$app->mailer->compose();
        $mail->setTo(['136101043@qq.com', 'everyone@cooldive.com.cn']);
        $mail->setSubject("酷潜业务 $type " . date('Y/m/d H:i:s'));
        $mail->setHtmlBody($msg.' '.$username);
        try {
            if (!$mail->send()) Yii::error('mail send fail', __METHOD__);
        } catch (\Exception $e) {
            Yii::error($e->getMessage(), __METHOD__);
        }
    }
}
